package com.slz3.business.module.messageManagement.mesUser.domain;

import com.slz3.business.frame.enums.AuditFlag;
import com.slz3.business.frame.enums.UsingFlag;
import com.slz3.business.frame.util.LocalDT;
import com.slz3.business.frame.util.UUIDUtils;
import com.slz3.business.frame.util.VE;
import com.slz3.business.module.drawManagement.draIntegralLottery.domain.DraIntegralLotteryCondition;
import org.springframework.util.MultiValueMap;

import java.time.LocalDateTime;

public class MesUserFactory {

    /**
     * 初始化基础属性值
     */
    public static MesUser initBaseFields(MesUser mesUser) {
        if (mesUser.getUuid() == null) {
            mesUser.setUuid(UUIDUtils.generateUUID());
            mesUser.setCreateTime(LocalDateTime.now());
            if (VE.isEmpty(mesUser.getSerAudit())) {
                mesUser.setSerAudit(AuditFlag.WAIT_SUBMIT);
            }
            if (VE.isEmpty(mesUser.getSerUsing())) {
                mesUser.setSerUsing(UsingFlag.ENABLE);
            }
        } else {
            mesUser.setLastModifyTime(LocalDateTime.now());
        }
        return mesUser;
    }

    /**
     * 初始化基础属性值
     */
    public static MesUser initBaseFields() {
        return initBaseFields(newTemStyle());
    }

    public static MesUser newTemStyle() {
        return new MesUser();
    }
    public static MesUserCondition newMesUserCondition(MultiValueMap<String, String> params) {
        MesUserCondition mesUserCondition = new MesUserCondition();

        String createTimeOUTSET = params.getFirst("serSendTimeOUTSET");
        String createTimeFINISH = params.getFirst("serSendTimeFINISH");


        mesUserCondition.setSerSendTimeStart(VE.isEmpty(createTimeOUTSET) ? null : LocalDT.parseStringToDateTime(createTimeOUTSET, DraIntegralLotteryCondition.CREATE_TIME_OF_PATTERN));
        mesUserCondition.setSerSendTimeEnd(VE.isEmpty(createTimeFINISH) ? null : LocalDT.parseStringToDateTime(createTimeFINISH, DraIntegralLotteryCondition.CREATE_TIME_OF_PATTERN));

         return mesUserCondition;
    }

}
